var search = {
    type: "form",
    name: "search",
    title: "赠品领用查询",
    isSearch: true,

    //calendar
    //-----------------------------------------------------------------------------------
    //定义子元素及布局模式
    //-----------------------------------------------------------------------------------
    items: [
    {
        type: "calendar",
        title: "开始日期",
        dataIndex: "beginDate"
    },{
        type: "calendar",
        title: "结束日期",
        dataIndex: "endDate"
    },{
        type: "input",
        title: "备注",
        dataIndex: "remark"
    }
    ],
    
    layoutConfig: {
        columns: 6
    },
    layout: [
    	{items: [{'name': '开始日期'},{'name': '结束日期'},{'name': '备注'}]}
    ]
};

var gridMain = {
    name: "gridMain",
    type: "grid",
    title: "赠品领用记录列表",
    pageSize: 13,
    haveCheckCol: false,
    autoFill: false,
    tbar: ['新增','-','删除'],
    bindRelation: {
        root: "dataset.financewastebookvo",
        id: "id",
        col: [
            {"header":"领用日期",   	"width":100,   "dataIndex":"inoutDate","renderer": Sail.formatDate},
            {"header":"领用额度(元)",   	"width":100,   "dataIndex":"money"},
            {"header":"经手人",   		"width":100,   "dataIndex":"creatorName"},
            {"header":"备注",   			"width":100,   "dataIndex":"remark"},
            {"header":"修改",       	"width":60,    "dataIndex":"id",   "actionCol"  :true,  "actionText" :"修改"}        
      	]
    }
};


var page1 = new Sail.page({
    name: "MianPage",
    mode: 'list',

    frames: {
        name: "MainFrame",
        title: "MainFrame",
        autoLoad: false,
        items: [search, gridMain],

        bindEvent2Items: function () {

          $('search').addButtonHandler('查询', function () {
              queryData();
          });

	        $('search').addButtonHandler('重置',function(){ 
	  		  	setDefaultValue(); 
		      });
		      
		      
					//删除
					$('gridMain').addButtonHandler('删除', function() {
						var ids=$('gridMain').getSelections("id").join(":");
						if (ids==''){
						   alert("请选择一条记录！");
						   return;
						 }
						if (confirm("确认要删除所选择的数据吗？")) {
							//var ids = grid.getSelections('id').join(':');
							Sail.postData('../../../DataMap?funcname=deleteFinanceWastebookList', {
								'ids' : ids
							}, function(flag, getData) {
									if (flag == "true") {
										Ext.Msg.alert("提示", "操作成功!");
										$('gridMain').load();
									} else {
										Ext.Msg.alert("警告",
												$('gridMain').dataset.response.content);
									}
								}
							);
						}
					});
					//新增页面
					$('gridMain').addButtonHandler('新增',function() {
						Sail.open("GiftAcountDetail.html", "add",{}, 600, 400);
						$('gridMain').load();
					});      
          
					$('gridMain').addAction('修改', function (id, row, record, value) {
						var data = {"id": id};
            Sail.open("GiftAcountDetail.html", "update", data , 600, 400);
            $('gridMain').load();
          });
        }
    }, 
    afterRun: function () {
			setDefaultValue();
      queryData();
    }
});


page1.run();


function queryData() {
    var searchInfo = $('search').getSearch();
    $('gridMain').load("../../../DataMap?funcname=fetchFinanceWastebookList&inoutType=InoutType_3&shopId=shop_wang_1&financeAccountType=77DBE19F4FF742F39C27BA8AD2070E7C" + searchInfo);
}

function setDefaultValue(){
	 $('开始日期').setValue(getCurrentDay());
	 $('结束日期').setValue(getCurrentDay());
}